﻿using SafoverWpfFw;
using System;
using System.Globalization;
using Safover.Lidar.DataContract;

namespace Safover.LidarCollector.Converter
{
    public class LidarWorkModeToStringConverter : BaseValueConverter<LidarWorkModeToStringConverter> 
    {
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return DoConvert(value, parameter);
        }

        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var str = value.ToString();
            switch (str)
            {
                case "定向":
                    return LidarWorkMode.Fixed;
                case "锥面":
                    return LidarWorkMode.Horizontal;
                case "剖面":
                    return LidarWorkMode.Vertical;
                case "走航":
                    return LidarWorkMode.Underway;
                case "多模式":
                    return LidarWorkMode.Multi;
                default:
                    return LidarWorkMode.Fixed;
            }
        }

        private object DoConvert(object value, object parameter)
        {
            var description = parameter == null ? "" : parameter.ToString();
            if (Enum.TryParse(value.ToString(), out LidarWorkMode lidarWorkMode))
            {
                switch (lidarWorkMode)
                {
                    case LidarWorkMode.Fixed:
                        return description + "定向";
                    case LidarWorkMode.Horizontal:
                        return description + "锥面";
                    case LidarWorkMode.Vertical:
                        return description + "剖面";
                    case LidarWorkMode.Underway:
                        return description + "走航";
                    case LidarWorkMode.Multi:
                        return description + "多模式";
                    default:
                        break;
                }
            }
            return "N/A";
        }

    }
}
